package com.wpl.fastec.latte.core.net;

import android.content.Context;

import com.wpl.fastec.latte.core.net.callback.IError;
import com.wpl.fastec.latte.core.net.callback.IFailure;
import com.wpl.fastec.latte.core.net.callback.IRequest;
import com.wpl.fastec.latte.core.net.callback.ISuccess;
import com.wpl.fastec.latte.core.ui.loader.LoaderStyle;

import java.io.File;
import java.util.Map;
import java.util.WeakHashMap;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class RestClientBuilder {

    private String mUrl;
    private static final Map<String, Object> PARAMS = RestCreator.getParams();
    private IRequest mIRquest;
    private ISuccess mISuccess;
    private IFailure mIFailure;
    private IError mError;
    private RequestBody mBody;
    private LoaderStyle mLoaderStyle;
    private Context mContext;
    private File mFIle;
    private  String mDownloadDir;
    private  String mExtension;
    private  String mName;

    RestClientBuilder() {
    }

    public final RestClientBuilder url(String url) {
        this.mUrl = url;
        return this;
    }

    public final RestClientBuilder params(WeakHashMap<String, Object> params) {
        PARAMS.putAll(params);
        return this;
    }

    public final RestClientBuilder params(String key,Object value) {
        PARAMS.put(key,value);
        return this;
    }

    public final RestClientBuilder request(IRequest iRequest){
        this.mIRquest = iRequest;
        return this;
    }

    public final RestClientBuilder raw(String raw) {
        this.mBody = RequestBody.create(MediaType.parse("application/json;charset=UTF-8"), raw);
        return this;
    }

    public final RestClientBuilder success(ISuccess iSuccess) {
        this.mISuccess = iSuccess;
        return this;
    }

    public final RestClientBuilder failure(IFailure iFailure){
        this.mIFailure = iFailure;
        return this;
    }
    public final RestClientBuilder file(File file){
        this.mFIle = file;
        return this;
    }

    public final RestClientBuilder file(String file){
        this.mFIle = new File(file);
        return this;
    }

    public final RestClientBuilder error(IError iError) {
        this.mError = iError;
        return this;
    }

    public final RestClientBuilder loader(Context context,LoaderStyle loaderStyle) {
        this.mLoaderStyle = loaderStyle;
        this.mContext = context;
        return this;
    }
    public final RestClientBuilder loader(Context context) {
        this.mLoaderStyle = LoaderStyle.BallClipRotatePulseIndicator;
        this.mContext = context;
        return this;
    }

    public final RestClientBuilder dir(String dir) {
        this.mDownloadDir = dir;
        return this;
    }

    public final RestClientBuilder extension(String extension) {
        this.mExtension = extension;
        return this;
    }

    public final RestClientBuilder name (String name) {
        this.mName = name;
        return this;
    }
    public final RestClient build(){
        return new RestClient(mUrl,PARAMS,mIRquest,mISuccess,mIFailure,mError,mBody,mLoaderStyle,mContext,mFIle,mDownloadDir,mExtension,mName);
    }


}
